package com.feng.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.feng.commonutils.R;
import com.feng.eduservice.entity.EduCourse;
import com.feng.eduservice.entity.EduTeacher;
import com.feng.eduservice.service.EduCourseService;
import com.feng.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;
    //查询前八条热门课程，查询前四名名师
    @GetMapping("index")
    public R index(){
        //查询前八条热门课程
        LambdaQueryWrapper<EduCourse> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(EduCourse::getId);
        queryWrapper.last("limit 8");
        List<EduCourse> eduCourses = eduCourseService.list(queryWrapper);
        //查询前四名名师
        LambdaQueryWrapper<EduTeacher> eduTeacherLambdaQueryWrapper=new LambdaQueryWrapper<>();
        eduTeacherLambdaQueryWrapper.orderByDesc(EduTeacher::getId);
        eduTeacherLambdaQueryWrapper.last("limit 4");
        List<EduTeacher> eduTeachers = eduTeacherService.list(eduTeacherLambdaQueryWrapper);
        return R.ok().data("eduCourses",eduCourses).data("eduTeachers",eduTeachers);
    }
}
